<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>LcsdAdmin</title>
    <link rel="stylesheet" href="{{URL::asset('/layui/css/layui.css')}}">
</head>
<body class="layui-layout-body" style="padding: 10px">
<form class="layui-form">
    <div class="layui-layout layui-layout-admin">
        <!-- 表单区域 -->
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                <input type="hidden" name="aid" value="">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-block">
                <select name="category" lay-verify="required">
                    <option value=""></option>
                    @foreach ($articlecategory as $v)
                        <option value="{{$v['id']}}">{{ $v['name'] }}</option>
                    @endforeach
                </select>
            </div>
        </div>


        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label" placeholder="请输入内容">内容</label>
            <div class="layui-input-block">
                <textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        {{--                <textarea id="demo" style="display: none;"></textarea>--}}
        <!-- 结束 -->


        <!-- 按钮区域 -->
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
        <!-- 结束 -->
    </div>
</form>
    <script src="{{URL::asset('/layui/layui.js')}}"></script>
    <script>

        function child(obj){
            var a = JSON.parse(obj);
        layui.use(['layer','form','layedit'], function(){
            var $ = layui.$; //加载layui
            var form = layui.form;  //加载form模块
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            var layedit = layui.layedit; // 加载layui 富文本编辑器
            var url = "{{url('admin/article/save')}}";
            $('input[name=aid]').val(a.id);
            $('input[name=title]').val(a.title);
            //form 提交表单
            form.on('submit(formDemo)', function(data){
                var detailDateStr = JSON.stringify(data.field)
                $.ajax({
                    url:url,
                    type:'post',
                    data:{
                        'data':detailDateStr,
                        '_token':'{{csrf_token()}}',
                        'type':'2',
                    },
                    success:function(data){
                        var info = JSON.parse(data);
                        if(info.code == 0){
                            layer.confirm("状态码："+info.code+",信息："+info.msg, {
                                btn: ['知道了'] //可以无限个按钮
                            }, function(index, layero){
                                parent.location.reload(); // 刷新父级页面
                                parent.layer.close(index); //关闭当前页面
                            });
                            return;
                        }
                        layer.alert("状态码："+info.code+",信息："+info.msg);return;
                    },
                });
                return false;
            });
            //建立编辑器    富文本编辑器
            layedit.build('demo',{

            });
        });
        };
    </script>
</body>
</html>
